package org.example.erp.controller;
import org.example.erp.domain.Material;
import org.example.erp.service.impl.MaterialServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api")
public class MaterialController {
    @Autowired
    private MaterialServiceImpl materialService;

    // 查询物料分类方法
    @GetMapping("/material/find")
    public DataResult findMaterial(@RequestParam(required = false) String materialName,@RequestParam(required = false) Integer status){
        List<Material> material = materialService.findMaterial(materialName, status);
        return DataResult.success(material);
    }

    // 添加物料分类方法
    @PostMapping("/material/insert")
    public DataResult insertMaterial(@RequestBody Material material){
        System.out.println("添加物料分类");
        materialService.save(material);
        return DataResult.success();
    }

    // 根据id删除物料分类方法
    @DeleteMapping("/material/delete")
    public DataResult deleteMaterial(@RequestParam Integer materialId){
        materialService.removeById(materialId);
        return DataResult.success();
    }

    // 修改物料分类方法
    @PutMapping("/material/update")
    public DataResult updateMaterial(@RequestBody Material material){
        materialService.updateById(material);
        return DataResult.success();
    }
}
